package test;

import static org.junit.Assert.assertTrue;
import main.*;
import movement.Location;

import org.junit.Before;
import org.junit.Test;

import unit.Garage;
import unit.PoliceCar;
import unit.Unit;
import dispatch.DispatchCenter;
import emergency.Emergency;
import emergency.Fire;
import emergency.PublicDisturbance;
import emergency.Robbery;
import emergency.Severity;
import emergency.TrafficAccident;

public class useCaseTestAdvanceSimulatedTime {
	FacadeDispatcher facade;
	Location justALocation;
	
	DispatchCenter center;
	Garage garage;
	
	Emergency em1, em2, em3, em4;
	Unit u1;
	
	@Before
	public void setUp() throws Exception {
		String args[] = new String[1];
		args[0] = "environment.dat";
		World world = new World(args);
		facade = new FacadeDispatcher(world);
		
		center = facade.getDispatchCenter();
		garage = center.getGarage();
		justALocation = new Location(10,10,"NameDoesn'tMatter");
		
		em1 = new Fire(justALocation, Severity.NORMAL, center, Fire.Size.HOUSE, true, 1, 1);
		em2 = new PublicDisturbance(justALocation, Severity.NORMAL, center, 1);
		em3 = new TrafficAccident(justALocation, Severity.NORMAL, center, 1, 1);
		em4 = new Robbery(justALocation, Severity.NORMAL, center, false, true);
		
		u1 = new PoliceCar("Police", 60, garage);
	}
	
	@Test
	public void testAdvanceTime() throws Exception{
		//check advance time with unit movement ! 

		facade.assignAllUnits(em3);
		
		Unit u = em3.getUnits().get(0);

		Garage uHomeLoc = u.getHomeLocation();
		
		center.getClock().advanceTime(100);
		
		//after 60 minutes, u is at the location of em3 
		assertTrue(u.getCurrentLocation().equals(em3.getLocation()));

		u.endEmergency();
		
		center.getClock().advanceTime(100);

		assertTrue(uHomeLoc.getLocation().equals(u.getCurrentLocation()));
	}
}
